package com.ruoyi.residential.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.residential.domain.TResidential;
import com.ruoyi.residential.service.ITResidentialService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * 小区列表Controller
 * 
 * @author ruoyi
 * @date 2025-09-10
 */
@RestController
@RequestMapping("/residential")
public class TResidentialController extends BaseController
{
    @Autowired
    private ITResidentialService tResidentialService;

    /**
     * 查询小区列表列表
     */
    @RequiresPermissions("residential:residential:list")
    @GetMapping("/list")
    public TableDataInfo list(TResidential tResidential)
    {
        startPage();
        List<TResidential> list = tResidentialService.selectTResidentialList(tResidential);
        return getDataTable(list);
    }

    /**
     * 导出小区列表列表
     */
    @RequiresPermissions("residential:residential:export")
    @Log(title = "小区列表", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TResidential tResidential)
    {
        List<TResidential> list = tResidentialService.selectTResidentialList(tResidential);
        ExcelUtil<TResidential> util = new ExcelUtil<TResidential>(TResidential.class);
        util.exportExcel(response, list, "小区列表数据");
    }

    /**
     * 获取小区列表详细信息
     */
    @RequiresPermissions("residential:residential:query")
    @GetMapping(value = "/{residentialId}")
    public AjaxResult getInfo(@PathVariable("residentialId") Long residentialId)
    {
        return success(tResidentialService.selectTResidentialByResidentialId(residentialId));
    }

    /**
     * 新增小区列表
     */
    @RequiresPermissions("residential:residential:add")
    @Log(title = "小区列表", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TResidential tResidential)
    {
        return toAjax(tResidentialService.insertTResidential(tResidential));
    }

    /**
     * 修改小区列表
     */
    @RequiresPermissions("residential:residential:edit")
    @Log(title = "小区列表", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TResidential tResidential)
    {
        return toAjax(tResidentialService.updateTResidential(tResidential));
    }

    /**
     * 删除小区列表
     */
    @RequiresPermissions("residential:residential:remove")
    @Log(title = "小区列表", businessType = BusinessType.DELETE)
	@DeleteMapping("/{residentialIds}")
    public AjaxResult remove(@PathVariable Long[] residentialIds)
    {
        return toAjax(tResidentialService.deleteTResidentialByResidentialIds(residentialIds));
    }
}
